<template>
  <el-table-column
    v-if="!column.noForCol"
    :show-overflow-tooltip="!colConfig.noTooltip&&true"
    :prop="column.prop"
    :label="column.label"
    :width="colConfig.width"
    :min-width="colConfig.minWidth"
    :fixed="colConfig.fixed"
    :align="colConfig.align || 'center'"
    :className="colConfig.className"
    :resizable="isResizable"
    :sortable="isSortable"
    :column-key="columnKey"
    :filters="filters"
    :filter-method="colConfig.filterMethod">
    <template slot-scope="scope">
      <mes-cell-comp
        :column="column"
        :colConfig="colConfig"
        :row="scope.row"
        @jump="$emit('jump', scope.row)"></mes-cell-comp>
    </template>
  </el-table-column>
</template>

<script>
export default {
  name: 'MesColComp',
  props: {
    column: {
      type: Object,
      default() {
        return {}
      }
    },
  },
  computed: {
    // 是否列筛选，默认false
    filterAble() {
      return this.column.filterAble || false
    },
    // 筛选返回的key，如果不在colConfig中指定则返回列的prop
    columnKey() {
      if (this.colConfig.columnKey) return this.colConfig.columnKey
      if (this.column.searchConfig) return this.column.prop
    },
    // 筛选项
    // 过滤掉全部选项
    // 3、转出text，value
    filters() {
      if (!this.filterAble) return undefined
      return this.dictArr.filter(v => v.label !== '全部').reduce((pre, cur) => [...pre, {
        text: cur.label,
        value: cur.id,
      }], [])
    },
    // 字典项
    // 1、searchConfig selectList
    // 2、searchConfig dict
    dictArr() {
      if (this.searchConfig.hasOwnProperty('selectList') && Array.isArray(this.searchConfig.selectList)) return this.searchConfig.selectList
      if (this.searchConfig.dict) return this.$store.state.dict[this.searchConfig.dict].labels || []
      return []
    },
    searchConfig() {
      return this.column.searchConfig || {}
    },
    colConfig() {
      return this.column.colConfig || {}
    },
    // 是否可拖拽列宽
    isResizable() {
      if (typeof this.colConfig.resizable === 'boolean') {
        return this.colConfig.resizable
      }
      return this.colConfig.fixed !== 'right'
    },
    // 是否可排序
    isSortable() {
      // 暂时在筛选时不排序
      if (this.column.filterAble === true) return false
      return (!this.colConfig.hasOwnProperty('sortable') && 'custom') || this.colConfig.sortable
    }
  },
}
</script>
